const _ = require("lodash");

// const url = 'http://test.k8s.w3.yiducloud.cn/'
// const url = "http://test.hnthih.yiducloud.cn/";

// const url = "http://globalwatch.bjcdc.org.cn/api";
// const cookie = "LOGIN_SESSION=NzRiN2YyMzktM2RiMC00M2Y0LWJhNDgtMTQ3YzI4ZDVhZWFi";

const url = "https://w3sichuan.yiducloud.com.cn/api";
const cookie = "ucenter_session=558694e72acebe43ddcdbe3792772af225a164021d9cadc905540c8197ea7e3c4774678269e473020b71c1e22224d77f332ea4da0cd04d35529863079923727cff71a80a5abae44d0a6a0dec6b16f554; CASTGT=TGT-Js2t4VvBOGjBYZMYo4JKn5tlLcBa1PHrCyjxX547rSFlViiRONFSKLBhBLf0; session=558694e72acebe43ddcdbe3792772af225a164021d9cadc905540c8197ea7e3c4774678269e473020b71c1e22224d77f1b228c2022ef581dd737448af3843f7d59899efe08d53ae0818ee8e0ef379cf9; osession=558694e72acebe43ddcdbe3792772af225a164021d9cadc905540c8197ea7e3c4774678269e473020b71c1e22224d77f1b228c2022ef581dd737448af3843f7d7a606b4fe6415533146ccd6d23c4f3aa; sso_usession=558694e72acebe43ddcdbe3792772af225a164021d9cadc905540c8197ea7e3c4774678269e473020b71c1e22224d77f1b228c2022ef581dd737448af3843f7d59899efe08d53ae0818ee8e0ef379cf9; JSESSIONID=3A59655B89C4336EBE4205AA982CB2EC; nginx_proxy_session=cQK_Mdf99X1BkcYwONMp6w..|1761360132|SiaU2U-gH-DwTde6ivmFvykTzzs.; web_nginx_info=tqJF0cm0HNMD/mnBRGjePLNglTrK+vZCMD+g5cqIU/w="
// const cookie =
//   "_ga=GA1.2.1630129991.1726295335; _clck=dihfwi%7C2%7Cfsl%7C0%7C1841; cna=84873042066b4bc3a978996074fcd369; nginx_proxy_session=CodjHWxRar42XaY9yS_V2Q..|1747450445|KG9f0Zh16zGEjX1ctnKD_EPl3B0.; web_nginx_info=QKhbRWxU5C+vGnDJfS3DiOormuBFzTcPzxiRGqt75zYnWBE3yf3ZWRCkaicTavfK; ucenter_session=64fbaabfb5e983dd1333aad1fe2b60b9b7b1bffe5e1afd6bc4640d8f385780f5d86ec9277b381f4470fb19de5eed90e2ab54dd80b439eb3645843d355d2b3fd3b80068027e25b7ac8ca3338bf9a41461; CASTGT=TGT-6sbUoudgVblBtkzuKxv9iKSjjhbmEjdDRkFEkS9e0Qc1xjIsdAOW3kcar7KN; session=64fbaabfb5e983dd1333aad1fe2b60b9b7b1bffe5e1afd6bc4640d8f385780f5d86ec9277b381f4470fb19de5eed90e2bd1e3175770a90ea3acc1123b4445a89281d777b0f496beb53af603c7e576e08; osession=64fbaabfb5e983dd1333aad1fe2b60b9b7b1bffe5e1afd6bc4640d8f385780f5d86ec9277b381f4470fb19de5eed90e2bd1e3175770a90ea3acc1123b4445a89a2cff1ff734cfb717cd497892e6b8e45; sso_usession=64fbaabfb5e983dd1333aad1fe2b60b9b7b1bffe5e1afd6bc4640d8f385780f5d86ec9277b381f4470fb19de5eed90e2bd1e3175770a90ea3acc1123b4445a89281d777b0f496beb53af603c7e576e08";

module.exports = {
  ..._.reduce(
    [
      "/api",
      "/ucenter",
      "/monitor_warning",
      "/epinews",
      "/gaia",
      "/bjcdc",
      "/sso",
      "/frontsso",
    ],
    (result, key) => {
      result[key] = {
        target: url,
        changeOrigin: true,
        onProxyReq(proxyRequest) {
          if (cookie) {
            proxyRequest.setHeader("cookie", cookie);
          }
        },
        onProxyRes: (proxyRes, req, res) => {
          const port = proxyRes.req.socket && proxyRes.req.socket.remotePort;
          // 记录代理后的实际请求地址
          console.log(
            `代理： ${proxyRes.req.protocol}//${proxyRes.req.host}${
              port ? ":" + port : ""
            }${proxyRes.req.path}`
          ); // 如 ' http://50.50.147.69:10000/api/some-api/xxxxx'
        },
      };
      return result;
    },
    {}
  ),
};
